package com.example.mywuran;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends Activity {
    EditText et_city;
    Button btn_query;
    TextView tv_result;
    QueryTask task;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        et_city = (EditText)findViewById(R.id.city);
        tv_result = (TextView)findViewById(R.id.result);
        btn_query = (Button)findViewById(R.id.query);

        btn_query.setOnClickListener(new OnClickListener() {
            public void onClick(View view) {
                String city = et_city.getText().toString();
                if (city.length() < 1) {
                    Toast.makeText(MainActivity.this, "请输入城市名",
                            Toast.LENGTH_LONG).show();
                    return;
                }
                task = new QueryTask(MainActivity.this, tv_result);
                task.execute(city);
            }
        });
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
//        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

}